#ifndef MONIERESDICT_H
#define MONIERESDICT_H
#include <QObject>
#include <QString>
#include <QStringList>
#include <QFile>
#include <QPair>
#include <QMultiHash>
#include <QList>

#include "dictionaryinterface.h"

typedef QPair<qint64, int> MonierESPosition;

typedef QMultiHash<QString, MonierESPosition > MonierESIndex;
typedef QMultiHash<QString, MonierESPosition >::iterator MonierESIndexIterator;
typedef QList<MonierESPosition> MonierESItemList;

class Transliterator;

class MonierESDict : public QObject, DictionaryInterface
{
    Q_OBJECT
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
    Q_PLUGIN_METADATA(IID "Abhidhaana.Plugin.DictionaryInterface/1.0" FILE "monieresdict.json")
#endif
    Q_INTERFACES(DictionaryInterface)

public:
    MonierESDict();
    ~MonierESDict();

    DictionaryDescription getDescription();

    void queryWord(QString key);


    QList<QPair<QString, QString> > getCandidateWords(QString key);

private:
    MonierESItemList findMonierESIndex(QString key);
    QString readMonierESContent(qint64 pos, int offset);
    QStringList findWords(QString key);
    MonierESIndex createMonierESIndex(QString idxfile);

    //Render.
    QString processLine(QString line);
    QString markup_body(QString string);

    Transliterator *transliterator;
    MonierESIndex idx;
    QFile *mweXml;
    QStringList allkey;

signals:
    void readyToShow(QString);
    //QString keyword;
};


#endif // MONIERESDICT_H
